import json
from selenium import webdriver
from selenium.webdriver.common.by import By

from requests_html import HTMLSession

headers = {
    'User_Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                  'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35'
}
session = HTMLSession()

# '''
#     使用requests_html直接获取页面上的元素
# '''
# # res = session.get(
# #     'https://jobs.51job.com/chengdu/148591658.html?s=sou_sou_soulb&t=0_0&req=e1ecc56c7f19c887e672ec6d7c2ea768')
# # find = res.html.find('div.tBorderTop_box')
# # print(find)
# '''
#     直接请求后台api
# '''
# params = {
#     'apiversion': 400,
#     'module': 'jobinfo',
#     'clientid': '000005',
#     'type__1260': 'eqAxcQqDwOG=3DsRhqGqODIrEKDOQDU2iD',
#     'data': {"jobid": "148591658",
#              "usertoken": "479e3ef963fd2fbcf81164207e0734c46461c712",
#              "hr": True},
#     'sign': 'fc617230b3139d32ea766ad9e130c245'
# }
# res = session.get("https://vapi.51job.com/job.php", params=params, headers=headers)
# print(res.text)
# '''
#     使用selenium进入详情页
# '''
# options = webdriver.EdgeOptions()
# options.add_experimental_option('detach', True)
# driver = webdriver.Edge(options=options)
# driver.get('https://jobs.51job.com/chengdu/148591658.html?s=sou_sou_soulb&t=0_0&req=e1ecc56c7f19c887e672ec6d7c2ea768')


for i in range(1, 2):
    params = {
        'pi_key': '51job',
        'timestamp': '1685417933',
        'searchType': 2,
        'function': '0107,0106,0121,0156,0157',
        'jobArea': '000000',
        'sortType': 0,
        'pageNum': {i},
        'pageSize': 20,
        'source': 1,
        'accountId': '226580376',
        'pageCode': 'sou|sou|soulb'
    }

    res = session.get("https://we.51job.com/api/job/search-pc", params=params, headers=headers)
    print(res.html.text)
    x = input()
    res = session.get("https://we.51job.com/api/job/search-pc", params=params, headers=headers)
    print(res.text)
    # job_list = (json.loads(res.text)).get("resultbody").get("job").get("items")
    # print(job_list)
